/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function (headA, headB) {
  let aHead = headA
  let bHead = headB
  while (aHead !== bHead) {
    if (aHead) {
      aHead = aHead.next
    } else {
      aHead = headB
    }
    if (bHead) {
      bHead = bHead.next
    } else {
      bHead = headA
    }
  }
  return aHead
};